package mytest.controller;



import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import test.testcase.dao.ChannelDao;
import test.utils.JsonResult;

@Controller @RequestMapping(value = "/channel", produces = "application/json; charset=utf-8")
@CrossOrigin
public class channel {
	
	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public @ResponseBody String list() {
		return ChannelDao.list().toResponse();
	}
	
	@RequestMapping(value = "/list/{id}", method = RequestMethod.GET)
	public @ResponseBody String list(HttpServletRequest request, @PathVariable String id) {
		return ChannelDao.list(id).toResponse();
	}
	
	@RequestMapping(value = "/add", method = RequestMethod.POST)
	public @ResponseBody String add(@RequestBody String body, HttpServletRequest request) {
		JsonResult result = JsonResult.parse(body);
		return ChannelDao.add(result.read("channelname").toString()).toResponse();
	}
	
	@RequestMapping(value = "/del/{id}", method = RequestMethod.GET)
	public @ResponseBody String del(HttpServletRequest request, @PathVariable String id) {
		return ChannelDao.del(id).toResponse();
	}
	
}
